﻿app.controller("comprasController", function ($scope, comprasService) {
    list = function () {
        comprasService.getListByFilter().then(function (r) {
            $scope.comprass = r.data;
        }, function (err) {
            console.log("Errrrr:" + err.data);
        });
    };
    list();
    $scope.save = function () {
        if ($scope.compras.id) {
            comprasService.update({ id: "" }, $scope.compras).then(function (r) {
                console.log("ru=" + r.data);
                $scope.compras = null;
                list();
            }, function (err) {
                console.log("Errrrr:" + err.data);
            });
        } else {
            comprasService.create($scope.compras).then(function (r) {
                console.log("rc=" + r.data);
                $scope.compras = null;
                list();
            }, function (err) {
                console.log("Errrrr:" + err.data);
            });
        }
    }
    $scope.delete = function (id) {
        comprasService.delete({ "id": id }).then(function (r) {
            console.log("rd=" + r.data);
            list();
        }, function (err) {
            console.log("Errrrr:" + err.data);
        });
    }
    $scope.selec = function (d) {
        $scope.compras = d;
    }
});